# -*- coding: utf-8 -*-
import scrapy
from mypjt.items import MypjtItem

class WeisuenSpider(scrapy.Spider):
    name = 'weisuen'
    allowed_domains = ['sina.com.cn']
    start_urls = ['http://www.sina.com.cn/',
                  'http://sports.sina.com.cn/nba/']

    def parse(self, response):
        item = MypjtItem()
        #test_data = []
        item["title"] = response.xpath("/html/head/title/text()")[0].extract()#[<Selector xpath='/html/head/title/text()' data='新浪首页'>]extract()将其中data内容提取出来
        #print("输出item.title]")
        #print(item["title"])
        #print("输出item=")
        #print(item)
        item["key"] = response.xpath("//meta[@name='keywords']/@content")[0].extract()
        
        #test_date.append(item)
        yield item  #将item数据推到pipelines,yield是一个生成器，可以多次将结果存到列表中进行推送
        #for i in range(10) :   #做个yield测试
         #   item["title"] = "hello-中文测试 % d" % i
          #  yield item